package net.sf.midollo.net;

import net.sf.midollo.io.system.SystemIOStreamFactory;
import net.sf.midollo.net.io.SocketIOStream;
import net.sf.midollo.net.protocol.ProtocolRunner;
import net.sf.midollo.net.protocol.tunnel.TunnelFactory;
import net.sf.midollo.utils.Utils;

import java.net.Socket;

public class Telnet {

	public static void main(String[] args) {
		try {

			String host = "127.0.0.1";
			String strPort = null;
			if (args.length >= 1)
				host = args[0];
			if (args.length >= 2)
				strPort = args[1];
			int port = Utils.parseInt(strPort, 23);

			Socket socket = new Socket(host, port);
			SocketIOStream socketIOStream = new SocketIOStream(socket);
			SystemIOStreamFactory systemIOStreamFactory = new SystemIOStreamFactory();
			TunnelFactory protocolFactory = new TunnelFactory(systemIOStreamFactory);
			ProtocolRunner protocolRunner = new ProtocolRunner(socketIOStream, protocolFactory);
			protocolRunner.runProtocol();

		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}
